package com.itheima.day08;

import com.itheima.domain.Student;
import com.itheima.util.RandomUtil;

import java.util.ArrayList;

public class Test03 {

    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();


        for (int i = 1; i <= 32; i++) {
            Student student = new Student();
            if (i <= 9) {
                student.setSid("A2021101900" + i);
            } else {
                student.setSid("A202110190" + i);
            }
            student.setName(RandomUtil.randomName());
            student.setGender(RandomUtil.randomGender());
            student.setBirthday(RandomUtil.randomBirthday());
            student.setGroup((i - 1) / 4 + 1);
            student.setPhone(RandomUtil.randomPhone());
            student.setWxs(RandomUtil.randomWxs());
            list.add(student);
        }
        for (Student student : list) {
            System.out.println(student);
        }
        // getNannv(list);
        //get00(list);
        //getMing(list);
        //getZhang(list);


        //
        //getPhone(list);
        //有2个的微信号的人个数  可以
        long count2Wx = list.stream().filter(s -> s.getWxs().size() == 2).count();
        //有1个的微信号的人个数   可以
        long count1Wx = list.stream().filter(s -> s.getWxs().size() == 1).count();
        System.out.println("有小号的有"+count2Wx);
        System.out.println("只有一个微信号的"+count1Wx);

    }

    public static void getPhone(ArrayList<Student> list) {
        //手机号中至少包含2个6的有哪些？  可以
        long count66 = list.stream().filter(s -> {
                    int count = 0;
                    String phone = s.getPhone();
                    char[] chars = phone.toCharArray();
                    for (int i = 0; i < chars.length; i++) {
                        if (chars[i] == '6') {
                            count++;
                        }
                    }
                    return count >= 2;
                }
        ).count();
        System.out.println(count66);
        //手机号中至少包含1个6和1个8的有哪些？  可以
        long count68 = list.stream().filter(s -> {
                    int count6 = 0;
                    int count8 = 0;
                    String phone = s.getPhone();
                    char[] chars = phone.toCharArray();
                    for (int i = 0; i < chars.length; i++) {
                        if (chars[i] == '6') {
                            count6++;
                        }
                        if (chars[i] == '8') {
                            count8++;
                        }
                    }
                    return count6 >= 1&&count8>=1;
                }
        ).count();
        System.out.println(count68);
    }

    public static void getZhang(ArrayList<Student> list) {
        //姓张的同学有多少人？  可以
        long countZhang = list.stream().filter(s -> s.getName().startsWith("张")).count();
        System.out.println(countZhang);
    }

    public static void getMing(ArrayList<Student> list) {
        //名字长度是2的学生有多少人？ 可以
        long countming2 = list.stream().filter(s -> s.getName().length() == 2).count();
        //名字长度是3的学生有多少人？ 可以
        long countming3 = list.stream().filter(s -> s.getName().length() == 3).count();
        System.out.println("名字是2个的" + countming2);
        System.out.println("名字是3个的" + countming3);
    }

    public static void get00(ArrayList<Student> list) {
        //00后有多少人？    可以
        long count00 = list.stream().filter(s -> s.getBirthday().getYear() >= 2000).count();
        System.out.println("00后:" + count00);
    }

    public static void getNannv(ArrayList<Student> list) {
        //男生和女生各自有多少人？    可以
      /*  int countNan=0;
        int countNv=0;
        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            String gender = student.getGender();
            if(gender.equals("男")){
                countNan++;
            }else {
                countNv++;
            }

        }*/
        long countNan = list.stream().filter(s -> s.getGender().equals("男")).count();
        long countNv = list.stream().filter(s -> s.getGender().equals("女")).count();
        System.out.println("男的:" + countNan);
        System.out.println("女的:" + countNv);
    }
}
